﻿using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.Entitys.Inv;
using Domain.IRepositorys.Inv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Inv
{
    /// <summary>
    /// 库存
    /// </summary>
    public class Inv_StockServices : IInv_StockServices
    {
        private readonly IInv_StockRepository inv_StockRepository;

        private readonly IMapper mapper;

        public Inv_StockServices(IInv_StockRepository inv_StockRepository, IMapper mapper)
        {
            this.inv_StockRepository = inv_StockRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 查看库存
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <param name="zone_code"></param>
        /// <param name="location_code"></param>
        /// <param name="por_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Getinv_stock(string weahouse_code, string por_code)
        {
            return inv_StockRepository.Getinv_stock(weahouse_code, por_code);
        }

      

        /// <summary>
        /// 根据仓库查询库存表里面的数据进行筛选产品
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<inv_stock>> Get_Select_weahouse_code(string weahouse_code, int currentPage, int pageSize)
        {
            return inv_StockRepository.Get_Select_weahouse_code(weahouse_code, currentPage, pageSize);
        }
        /// <summary>
        /// 查询仓库内商品数量
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Get_Select_Weahouse_code_Count(string weahouse_code)
        {
            return inv_StockRepository.Get_Select_Weahouse_code_Count(weahouse_code);
        }


        /// <summary>
        /// 根据仓库查询库存表里面的数据进行筛选产品--添加产品编码和字典编码的条件
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <param name="pro_code"></param>
        /// <param name="dict_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public Task<List<inv_stock>> Get_Select_stock_All(string weahouse_code, string pro_code, int dict_code, int currentPage, int pageSize) { 
        
            return inv_StockRepository.Get_Select_stock_All(weahouse_code, pro_code, dict_code, currentPage, pageSize);
        }


        /// <summary>
        /// 查询库存里面的数据总数--添加二个条件 产品码编码
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <returns></returns>
        public Task<int> Get_Select__stock_Count(string weahouse_code, string pro_code, int dict_code) { 
        
        return inv_StockRepository.Get_Select__stock_Count(weahouse_code, pro_code, dict_code);
        }

        /// <summary>
        /// 盘亏--修正库存
        /// </summary>
        /// <param name="inv_stock"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Update_inv_Stock_numder(List<Inv_Stock_numderUpdateDto> inv_stock)
        {

            var emtit = inv_stock.Select(Dto => new Inv_Stock_numderUpdateDto {
                Warehouse_Code = Dto.Warehouse_Code,
                Zone_Code = Dto.Zone_Code,
                Location_Code = Dto.Location_Code,
                pro_code = Dto.pro_code,
                stock_numder = Dto.stock_numder
            }).ToList();

            return await inv_StockRepository.Update_inv_Stock_numder(emtit);
    }
        /// <summary>
        /// 修改库存调拨 
        /// </summary>
        /// <param name="Stock_UpdateTrfDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> stock_Update_kc(List<Stock_UpdateTrfDto> Stock_UpdateTrfDto)
        {
            return await inv_StockRepository.stock_Update_kc(Stock_UpdateTrfDto);
        }
        /// <summary>
        /// 根据查询库存--详情页面
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <param name="por_code"></param>
        /// <param name="stock_entry_no"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Getinv_stock_XQ(string weahouse_code, string por_code, string stock_entry_no)
        {
            return inv_StockRepository.Getinv_stock_XQ(weahouse_code, por_code, stock_entry_no);
        }
        /// <summary>
        /// 获取商品所有下面的产品库存--产品编码
        /// </summary>
        /// <param name="Pro_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Get_inv_stock_totalnumber(string Pro_code)
        {
            return inv_StockRepository.Get_inv_stock_totalnumber(Pro_code);
        }
        /// <summary>
        /// 结构入库编号,产品编号,仓库编号去查询这个产品在的库位和库区
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <param name="pro_code"></param>
        /// <param name="stock_entry_no"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<inv_stock>> Get_Select_stock_All_By_Pro_Code(string weahouse_code, string pro_code, string stock_entry_no)
        {
            return inv_StockRepository.Get_Select_stock_All_By_Pro_Code(weahouse_code, pro_code, stock_entry_no);
        }
        /// <summary>
        /// 其他出库单--出库减少库存
        /// </summary>
        /// <param name="inv_StockothoutordUpdateDtos"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Stock_update(List<Inv_stockothoutordUpdateDto> inv_StockothoutordUpdateDtos)
        {
            var entities = inv_StockothoutordUpdateDtos.Select(dto => new inv_stock
            {
                pro_code = dto.pro_code,
                Warehouse_Code=dto.Warehouse_Code,
                Zone_Code=dto.Zone_Code,
                Location_Code=dto.Location_Code,
                stock_entry_no=dto.stock_entry_no,
                stock_numder=dto.stock_numder
            }).ToList();
            return inv_StockRepository.Stock_update(entities);
        }





        /// <summary>
        /// 根据仓库查询库存表里面的数据进行筛选产品--仓库库存模块
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <returns></returns>

        public Task<List<inv_stock>> Get_Select_stock(string weahouse_code, string zone_code, string location_code, string Vendor_Code, string pro_code, int currentPage, int pageSize) { 
        
        return inv_StockRepository.Get_Select_stock(weahouse_code, zone_code, location_code, Vendor_Code, pro_code, currentPage, pageSize);
        }


        /// <summary>
        /// 查询仓库表的数据--仓库库存模块
        /// </summary>
        /// <param name="weahouse_code"></param>
        /// <returns></returns>
        public Task<int> Get_Select_stock_count(string weahouse_code, string zone_code, string location_code, string Vendor_Code, string pro_code) { 
        
        return inv_StockRepository.Get_Select_stock_count(weahouse_code, zone_code, location_code, Vendor_Code, pro_code);
        }


        /// <summary>
        /// 选择期初入库的时候--有动态的展示库存数量
        /// </summary>
        /// <param name="warehouse_code"></param>
        /// <param name="zone_code"></param>
        /// <param name="location_code"></param>
        /// <param name="pro_code"></param>
        /// <returns></returns>
        public Task<decimal> int_stock_numder(string warehouse_code, string zone_code, string location_code, string pro_code) { 
        
        return inv_StockRepository.int_stock_numder(warehouse_code, zone_code, location_code, pro_code);
        }

        /// <summary>
        /// 修改库存的数据不合格数量
        /// </summary>
        /// <param name="prodInfo_totnum_uqual"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        //public async Task<int> stock_Update_stockUnqualified_numder(List<Inv_StockUpdateDto> Inv_StockUpdateDto)
        //{
        //   return await inv_StockRepository.stock_Update_stockUnqualified_numder(Inv_StockUpdateDto);
        //}
    }
}
